﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YGWebMobileApi.Data;
using OneMile.BLL;
using OneMile.Common;

namespace YGWebMobileApi.APIs
{
    [MobileAPI(Code = "MC0005", Name = "取消收藏")]
    public class UDelFavorite :BaseAPI ,IProcessMessage
    {
        private BLLUFavorites bllUFav;
        public BLLUFavorites BllUFav
        {
            get
            {
                if (bllUFav == null)
                    bllUFav = BLLFactory.getInstance().CreateUFavoritesBLL();
                return bllUFav;
            }
        }

        #region IProcessMessage 成员
        public MobileRspMsg ProcessMessage(MobileReqMsg reqMsg)
        {
            try
            {
                MobileRspMsg rspMsg = new MobileRspMsg(reqMsg);
                // 获取参数字段（具体请参见文档）
                string userCollectionId = reqMsg.Body.GetFieldValue("UserCollectionId");
              
                if (string.IsNullOrEmpty(userCollectionId))
                {
                    rspMsg.Head.RspCode = MessageCode.Paramter_Empty.Code;
                    rspMsg.Head.RspMsg = MessageCode.Paramter_Empty.Msg;
                    return rspMsg;
                }

                if (BllUFav.DelFavorite(userCollectionId))
                {
                    rspMsg.Head.RspCode = MessageCode.Success.Code;
                    rspMsg.Head.RspMsg = MessageCode.Success.Msg;

                    return rspMsg;
                }
                else
                {
                    rspMsg.Head.RspCode = MessageCode.Server_Error.Code;
                    rspMsg.Head.RspMsg = MessageCode.Server_Error.Msg;

                    return rspMsg;
                }
            }  
            catch (Exception e)
            {
                ErrorLogWriter.Write("UDelFavorite-" + e);
                throw e;
            }

        }
        #endregion
    }
}